//
//  SpalshViewController.m
//  高大上
//
//  Created by 宗镇荣 on 16/2/19.
//  Copyright © 2016年 zzr. All rights reserved.
//

#import "SpalshViewController.h"
#import "CommonDefin.h"
#import "ZWIntroductionViewController.h"
#import "SortViewController.h"
#import "GoodsViewController.h"
#import "Personnal\ViewController.h"
#import "SaturdayViewController.h"
#import "AppDelegate.h"

@interface SpalshViewController ()

@property (nonatomic) ZWIntroductionViewController *introductionView;

@end

@implementation SpalshViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    if ([self isFirstStartApp]) {
//        [self showGuide];
//    } else {
//    
//        [self goMain];
//    }
    [self goMain];
}

- (void)goMain {

    NSArray *titles = @[@"666", @"单品", @"分类", @"喜爱"];
    NSArray *normalArray = @[@"common_tabBar_homeIcon",@"common_tabBar_discoveryIcon",@"common_tabBar_personalCenterIcon"];
    NSArray *selectArray = @[@"common_tabBar_homeIcon_light",@"common_tabBar_discoveryIcon_light",@"common_tabBar_personalCenterIcon_light"];
    SaturdayViewController *satVc = [[SaturdayViewController alloc] init];
    GoodsViewController *goodsVc = [[GoodsViewController alloc] init];
    SortViewController *sortVc = [[SortViewController alloc] init];
    Personnal_ViewController *personnalVc = [[Personnal_ViewController alloc] init];
    
    UINavigationController *satNa  = [[UINavigationController alloc] initWithRootViewController:satVc];
    UINavigationController *goodsNa  = [[UINavigationController alloc] initWithRootViewController:goodsVc];
//    UINavigationController *sortNa = [[UINavigationController alloc] initWithRootViewController:sortVc];
    UINavigationController *personnalNa = [[UINavigationController alloc] initWithRootViewController:personnalVc];
    satNa.tabBarItem = [[UITabBarItem alloc] initWithTitle:titles[0] image:[UIImage imageNamed:normalArray[0]] selectedImage:[UIImage imageNamed:selectArray[0]]];
    goodsNa.tabBarItem = [[UITabBarItem alloc] initWithTitle:titles[1] image:[UIImage imageNamed:normalArray[1]] selectedImage:[UIImage imageNamed:selectArray[1]]];
    //sortNa.tabBarItem = [[UITabBarItem alloc] initWithTitle:titles[2] image:[UIImage imageNamed:normalArray[2]] selectedImage:[UIImage imageNamed:selectArray[2]]];
    personnalNa.tabBarItem = [[UITabBarItem alloc] initWithTitle:titles[3] image:[UIImage imageNamed:normalArray[2]] selectedImage:[UIImage imageNamed:selectArray[2]]];
    
    UITabBarController *tabVc = [[UITabBarController alloc] init];
    
    tabVc.viewControllers = @[satNa, goodsNa, personnalNa];
    AppDelegate *de = [UIApplication sharedApplication].delegate;
    de.window.rootViewController = tabVc;
}

- (void)showGuide {

    NSArray *imageArray = @[@""];
    self.introductionView = [[ZWIntroductionViewController alloc] initWithCoverImageNames:imageArray];
    [self.view addSubview:self.introductionView.view];
    __weak typeof(self) weakSelf = self;
    self.introductionView.didSelectedEnter = ^() {
    
        weakSelf.introductionView = nil;
        [weakSelf goMain];
    };
    
    
}

- (BOOL)isFirstStartApp {

    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    NSNumber *number = [userDefault objectForKey:kAppFirstLoadKey];
    if (number != nil) {
        
        NSInteger startNumber = [number integerValue];
        NSString *str =  [NSString stringWithFormat:@"%ld", ++startNumber];
        [userDefault setObject:str forKey:kAppFirstLoadKey];
        [userDefault synchronize];
    }else {
    
        QFLog(@"%@",@"用户第一次启动");
        [userDefault setObject:@"1" forKey:kAppFirstLoadKey];
        [userDefault synchronize];
    }
    return YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
